use Modern::Perl;
use Mail::Box::Manager;
use Test::More;
use IO::All;

my $mgr=Mail::Box::Manager->new();
#note explain $mgr;
my $folder = $mgr->open(folder=>"imap4://bixichao:abc123\@mail.berrygenomics.com/test",access=>"rw");

my @messages = grep { 
  $_->get("From") =~ /bixichao\@berrygenomics\.com/ && $_->isMultipart();
} $folder->messages( "seen" );

my @parts = $messages[0]->parts;
note explain @parts;
for my $part (@parts) {
  my $disposition = $part->head->get('Content-Disposition');
  next unless $disposition =~ /attachment/;
  note $disposition;
  my ($filename) = $disposition =~ /filename=(.*)/;
  note $filename;
  my $attached = $part->decoded;
  my $report = io->catfile(io->dir("/home/bixichao/Documents/Study/Mail::Module/"),$filename)->assert;
  $report->print($attached)->close;
}
$messages[0]->label('seen' => 1);


$folder->close;
done_testing()
